package com.fauks.ee.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzMain {
    public static void main(String[] args) throws SchedulerException {
        System.out.println("开启定时任务");
        //创建job对象
        JobDetail job = JobBuilder.newJob(MyJob.class).build();
        //简单的trigger触发时间
        /*Trigger trigger = TriggerBuilder.newTrigger()
                //每2s执行一次
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(2))
                .build();*/
        //使用cron表达式
        Trigger trigger = TriggerBuilder.newTrigger()
                //每2s执行一次
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();
        //创建Scheduler对象
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    }
}
